<#include "/common/_layout.html"/> <@layout>

<header id="header" class="bg-primary" style="margin-bottom:45px;">
	<div class="navbar navbar-inverse navbar-fixed-top" id="navbar" role="banner" style="">
		<div class="container">
			<div class="navbar-header">
				<button class="navbar-toggle collapsed" type="button" data-toggle="collapse"
				data-target=".zui-navbar-collapse">
					<span class="sr-only">切换导航</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a href="/" class="navbar-brand"><span class="path-zui-36"><i class="path-1"></i><i class="path-2"></i></span> <span class="brand-title">宁美国度</span> &nbsp; <small class="zui-version"></small> <i data-toggle="tooltip" id="compactTogger" data-placement="bottom" class="icon icon-home"
				data-original-title="" title=""></i></a>
			</div>
			<nav class="collapse navbar-collapse zui-navbar-collapse">
				<ul class="nav navbar-nav navbar-right">
					<li>
						<a title="商品评价" href="" target="_blank"><i
						class="icon icon-download-alt"></i><span>商品评价</span></a>
					</li>
				</ul>
			</nav>
		</div>
	</div>
</header>
<div class="example">
	<div class="panel-group" id="accordion">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="panel-title">
          <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="collapsed">数据采集</a>
        </h4>
      </div>
      <div id="collapseOne" class="panel-collapse fade collapse" style="height: 0px;">
        <div class="panel-body">
         	<form class="form-horizontal" id="searchForm" role="form" method="post">
				<div class="form-group">
					<label class="col-md-2 control-label">Cookie</label>
					<div class="col-md-8">
						<textarea class="form-control" name="cookie" id="cookie" rows="2"
	                                  placeholder=""
	                                  style="margin-top: 0px; margin-bottom: 0px; height: 150px;"></textarea>
					</div>
				</div>
				<div class="form-group">
					<div class="col-md-offset-2 col-md-4">
						<input type="button" id="checkCookie" class="btn btn-primary" value="1、检查Cookie" data-loading="稍候...">
						<input type="button" id="saveCookie" class="btn btn-primary" value="2、保存Cookie" data-loading="稍候...">
						<input type="button" id="getDsrData" class="btn btn-primary" value="3、采集最新数据" data-loading="稍候...">
					</div>
					<div class="col-md-offset-2 col-md-4">
						<span id="cookieStatus" class="label">待检测</span>
					</div>
				</div>
			</form>
        </div>
      </div>
    </div>
    
  </div>
	
		
</div>
<div class="example">
	<div class="panel-group" id="accordion">
	<div class="row">
        <div class="col-md-4">
			<label class="col-md-2 control-label">采集日期</label>
	        <div class="input-group date form-date" data-date="" data-date-format="dd MM yyyy" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
	        	<input class="form-control" size="16" type="text" value="" readonly="">
	            <span class="input-group-addon"><span class="icon-remove"></span></span>
	            <span class="input-group-addon"><span class="icon-calendar"></span></span>
	    	</div>
        </div>
        <div class="col-md-offset-2 col-md-4">
			<input type="button" id="getDataByDate" class="btn btn-primary" value="按日期查询" data-loading="稍候...">
		</div>
      </div>
	</div>
</div>
<div class="example">
	<div class="panel-group" id="accordion">
		<section>
		<div id="dtGridContainer" class="dt-grid-container"></div>
		<div id="dtGridToolBarContainer" class="dt-grid-toolbar-container"></div>
		</section>
	</div>
</div>
<footer class="footer">
	<div class="container">
		<p>
			Copyright ©2015-2016 武汉宁美国度科技有限公司 版权所有
		</p>
	</div>
</footer>
<style>
	.footer {
		padding: 30px 0;
		margin-top: 70px;
		border-top: 1px solid #e5e5e5;
		background-color: #145ccd;
		border-color: #10479f;
		width: 100%;
		color: white;
	}

	.footer p {
		margin: 0px;
		padding: 0px;
	}
	
	.navbar-inverse {
		background-color:#145ccd;
		border-color: #FFFFFF;
	}
	.navbar-inverse .navbar-brand {
		color: #F7F7F7;
	}
	.nnavbar-right {
		color: #F7F7F7;
	}
	
</style>

<script type="text/javascript">
	
	$(document).attr('title','商品评价(DSR)');
	
	var orderStatus = {'-1':'下降' , '1':'上升'};
	var dtGridColumns = [
					{id:'statis_date', title:'日期', type:'date',format:'yyyy-MM-dd', otype:'string', oformat:'yyyy-MM-dd',columnClass:'text-center'},
                 	{id:'item_id', title:'宝贝ID', type:'string', columnClass:'text-center'},
                	{id:'item_title', title:'宝贝名称', type:'string', columnClass:'text-left'},
                	{id:'dsr', title:'DSR', type:'number', format:'###.0000', columClass:'text-center'},
                	{id:'review_cnt', title:'评价次数', type:'string', columnClass:'text-left'},
                	{id:'review_cnt_up', title:'评价周环比', codeTable:orderStatus,type:'string', columnClass:'text-left'},
                	{id:'manual_rate', title:'主动评价占比', type:'string', columnClass:'text-left'},
                	{id:'scan_rate_mobile', title:'移动端围观人数占比', type:'string', columnClass:'text-left'},
                	{id:'scan_rate_pc', title:'PC端围观人数占比', type:'string', columnClass:'text-left'},
                	{id:'create_date', title:'采集时间', type:'date',format:'yyyy-MM-dd hh:mm:ss',columnClass:'text-center'}
	];
	
	var dtGridOption = {
		lang : 'zh-cn',
		ajaxLoad : true,
		loadURL : '${CPATH}/dsr/getNewDsrDataJson',
		check : true,
		exportFileName : '商品DSR列表',
		columns : dtGridColumns,
		gridContainer : 'dtGridContainer',
		toolbarContainer : 'dtGridToolBarContainer',
		tools : 'export[excel,csv,pdf,txt]',
		pageSize : 10,
		pageSizeLimit : [10, 20, 50],
	};
	
	var grid = $.fn.DtGrid.init(dtGridOption);
	
	
	$(function(){
		//参数传递
		grid.parameters = new Object();
		
		NProgress.start();
		getCookie();
		var cookie = $('#cookie').val();
		if(cookie.length > 0){
			checkCookie();
		}
		//绑定方法
		$('#checkCookie').click(checkCookie);
		$('#saveCookie').click(saveCookie);
		
		$('#getDsrData').click(getNewDsrDataAndShow);
		$('#getDataByDate').click(getDataByDate);
		
		grid.load();
		
		
		
		// 仅选择日期
		$(".form-date").datetimepicker(
		{
		    language:  "zh-CN",
		    weekStart: 1,
		    todayBtn:  1,
		    autoclose: 1,
		    todayHighlight: 1,
		    startView: 2,
		    minView: 2,
		    forceParse: 0,
		    format: "yyyy-mm-dd"
		});
		
		var today = new Date().format("yyyy-MM-dd");    
		$(".form-date input").val(today);
		
		
		NProgress.done();
		
	});
	
	function getDataByDate(){
		var statis_date = $(".form-date input").val();
		if(statis_date || typeof(statis_date)=="undefined"){
			grid.parameters['statis_date'] = statis_date;
			grid.load();
		}else{
			showMassage("日期不能为空",null, null, "warning");
		}
	}
	
	//采集最新数据并显示
	function getNewDsrDataAndShow(){
		NProgress.start();
		
		var ii = layer.load();  
		$.ajax({   
				url:'${CPATH}/dsr/getNewDsrData',   
				type:'post',
				async : true, //默认为true 异步   
				error:function(){   
					showMassage("采集失败",null, null, "warning");  
				},   
				success:function(data){
					if(data.Code == 1){
						showMassage(data.Msg,null, null, "success");
						setTimeout(function(){
        					layer.close(ii);
    					}, 1000);
    					grid.load();
					}else{
						showMassage(data.Msg,null, null, "warning");
						setTimeout(function(){
        					layer.close(ii);
    					}, 1000);
					}
								
				}
			});
		

		NProgress.done();
	}
	
	//从配置加载最新保存的cookie
	function getCookie(){
		NProgress.start();
		$.getJSON('${CPATH}/dsr/getNewDsrCookie', function (data) { 
			if(data.Success){ 
            	$('#cookie').val(data.Data);
           	}
        }); 
        NProgress.done();
	}
	
	//检查cookie是否有效
	function checkCookie(){
		NProgress.start();
		var cookie = $('#cookie').val();
		if(cookie.length > 0){
			$.ajax({   
				url:'${CPATH}/dsr/checkDsrCookie',   
				type:'post',   
				data:{
					cookie:cookie
				},   
				async : true, //默认为true 异步   
				error:function(){   
					showMassage("查询失败",null, null, "warning");  
				},   
				success:function(data){  
					if(data.Code == 1){
						showMassage(data.Msg,null, null, "success");
						$('#cookieStatus').html('检测成功');
						$('#cookieStatus').attr("class","label label-success");
					}else{
						showMassage(data.Msg,null, null, "warning");
						$('#cookieStatus').html('检测失败');
						$('#cookieStatus').attr("class","label label-danger");
					}
					
				}
			});
		}else{
			showMassage("Cookie为空",null, null, "warning");
		}
		NProgress.done();
	};
	
	//保存Cookie到配置
	function saveCookie(){
		NProgress.start();
		var cookie = $('#cookie').val();
		if(cookie.length > 0){
			$.ajax({   
				url:'${CPATH}/dsr/saveDsrCookie',   
				type:'post',   
				data:{
					cookie:cookie
				},   
				async : true, //默认为true 异步   
				error:function(){   
					showMassage("保存失败",null, null, "warning");  
				},   
				success:function(data){  
					if(data.Code == 1){
						showMassage(data.Msg,null, null, "success");
				}else{
						showMassage(data.Msg,null, null, "warning");
					}
					
				}
			});
		}else{
			showMassage("Cookie为空",null, null, "warning");
		}
		NProgress.done();

	};

 	//使用ZUI消息弹出框
    //message 显示消息
    //placement 弹框显示位置  'bottom'|'top-left'|'top-right'|'bottom-left'|'bottom-right'|'center' 默认:top
    //time 弹框展现后多少秒后消失 默认为5秒(单位/毫秒)
    //type 弹框类型 'default'(默认)|'primary'|'success'|'info'|'warning'|'danger'|'important'|'special'
    function showMassage(message, placement, time, type) {
        if (typeof(placement) == "undefined" || typeof(placement) == "object") {
            placement = 'top';
        }
        if (typeof(time) == "undefined" || typeof(time) == "object") {
            time = 5000;
        }
        var msg = new $.zui.Messager(message, {placement: placement, time: time, type: type});
        msg.show();
    }
    
    // 对Date的扩展，将 Date 转化为指定格式的String   
	// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，   
	// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)   
	// 例子：   
	// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423   
	// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18   
	Date.prototype.Format = function(fmt)   
	{ //author: meizz   
	  var o = {   
	    "M+" : this.getMonth()+1,                 //月份   
	    "d+" : this.getDate(),                    //日   
	    "h+" : this.getHours(),                   //小时   
	    "m+" : this.getMinutes(),                 //分   
	    "s+" : this.getSeconds(),                 //秒   
	    "q+" : Math.floor((this.getMonth()+3)/3), //季度   
	    "S"  : this.getMilliseconds()             //毫秒   
	  };   
	  if(/(y+)/.test(fmt))   
	    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
	  for(var k in o)   
	    if(new RegExp("("+ k +")").test(fmt))   
	  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
	  return fmt;   
	}  
    
</script>

</@layout>